package com.jingsheng.jingshengcity.mvp.ui.fragment.tab;

import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.jess.arms.base.BaseFragment;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.utils.UiUtils;
import com.jingsheng.jingshengcity.R;
import com.jingsheng.jingshengcity.di.component.DaggerDiscoverFragmentComponent;
import com.jingsheng.jingshengcity.di.module.DiscoverFragmentModule;
import com.jingsheng.jingshengcity.mvp.contract.DiscoverFragmentContract;
import com.jingsheng.jingshengcity.mvp.presenter.DiscoverFragmentPresenter;
import com.jingsheng.jingshengcity.mvp.ui.adapter.DiscoverTabAdapter;

import butterknife.BindView;

import static com.jess.arms.utils.Preconditions.checkNotNull;

/**
 * Created by Administrator on 2017/5/5.
 */

public class DiscoverFragment extends BaseFragment<DiscoverFragmentPresenter> implements DiscoverFragmentContract.View {


    @NonNull
    @BindView(R.id.tab_layout)
    TabLayout mTabLayout;
    @NonNull
    @BindView(R.id.vp_fragment)
    ViewPager mViewPager;

    private String mTabTitle[] = new String[]{"促销活动", "商家店铺", "吃喝玩乐", "酒店住宿"};

    public static DiscoverFragment newInstance() {
        DiscoverFragment fragment = new DiscoverFragment();
        return fragment;
    }

    @Override
    public void setupFragmentComponent(AppComponent appComponent) {
        DaggerDiscoverFragmentComponent
                .builder()
                .appComponent(appComponent)
                .discoverFragmentModule(new DiscoverFragmentModule(this))//请将DiscoverFragmentModule()第一个首字母改为小写
                .build()
                .inject(this);
    }

    @Override
    public View initView(LayoutInflater inflater, ViewGroup container) {
        return inflater.inflate(R.layout.fragment_discover, container, false);
    }

    @Override
    public void initData() {
        DiscoverTabAdapter adapter = new DiscoverTabAdapter(getChildFragmentManager(), mTabTitle);
        mViewPager.setAdapter(adapter);
        mViewPager.setOffscreenPageLimit(mTabTitle.length);
        mTabLayout.setupWithViewPager(mViewPager);
    }

    @Override
    public void setData(Object data) {

    }


    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void showMessage(@NonNull String message) {
        checkNotNull(message);
        UiUtils.SnackbarText(message);
    }

    @Override
    public void launchActivity(@NonNull Intent intent) {
        checkNotNull(intent);
        UiUtils.startActivity(intent);
    }

    @Override
    public void killMyself() {

    }

}